﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;

namespace ChequeManagement.PL.PayAndReceiveItem
{
    public partial class PayAndReceiveItem : Form
    {
        public PayAndReceiveItem()
        {
            InitializeComponent();
        }
        ChequeManagement.BLL.BLLPayAndReceiveItem PayAndreceiveItemObject = new ChequeManagement.BLL.BLLPayAndReceiveItem();
        ChequeManagement.BLL.BLLPayAndRecieveItemFactory PayAndRecieveItemFactoryObject = new BLL.BLLPayAndRecieveItemFactory();
        private void button1_Click(object sender, EventArgs e)
        {
            //DataTable DT = new DataTable();
            //DT = PayAndRecieveItemFactoryObject.GetAllDT();
            //dataGridView1.DataSource = null;
            //dataGridView1.DataSource = DT;
        }
        public enum enumobj
        {
            DeliverReturned,
            DirectCash,
            DirectReceipt,
            DirectReturn,
            Dispensed,
            Gived,
            InReceipt,
            NotPayed,
            NotReceipt,
            Payed,
            Receipt,
            Retrieve,
            Returned
        }
        private void button2_Click(object sender, EventArgs e)
        {
           // System.Globalization.PersianCalendar pc = new System.Globalization.PersianCalendar();
            
            try
            {

                PayAndreceiveItemObject.AcountNo = long.Parse(textBox1.Text);
                PayAndreceiveItemObject.ChequeNo = long.Parse(textBox2.Text);
                PayAndreceiveItemObject.Amount = decimal.Parse(textBox3.Text);
                PayAndreceiveItemObject.BranchName = textBox4.Text.Trim();
                PayAndreceiveItemObject.BankID = 1;
                PayAndreceiveItemObject.DateOfIssue = Convert.ToDateTime(maskedTextBox1.Text);
                PayAndreceiveItemObject.Description = textBox7.Text.Trim();
                PayAndreceiveItemObject.Payee = textBox8.Text.Trim();
                PayAndreceiveItemObject.Status = (BLL.ChequeStatus)enumobj.DirectReturn;
                PayAndreceiveItemObject.PayAndReceiveID = 1;
                PayAndRecieveItemFactoryObject.Add(PayAndreceiveItemObject);
                MessageBox.Show("Insert");

            }
            catch (SqlException ex)
            {

                MessageBox.Show(ex.Message);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }

        private void button3_Click(object sender, EventArgs e)
        {
            try
            {
                PayAndreceiveItemObject.AcountNo = long.Parse(textBox1.Text);
                PayAndreceiveItemObject.ChequeNo = long.Parse(textBox2.Text);
                PayAndreceiveItemObject.Amount = decimal.Parse(textBox3.Text);
                PayAndreceiveItemObject.BranchName = textBox4.Text.Trim();
                PayAndreceiveItemObject.BankID = 1;
                PayAndreceiveItemObject.DateOfIssue = Convert.ToDateTime(maskedTextBox1.Text);
                PayAndreceiveItemObject.Description = textBox7.Text.Trim();
                PayAndreceiveItemObject.Payee = textBox8.Text.Trim();
                PayAndreceiveItemObject.Status = (BLL.ChequeStatus)enumobj.Gived;
                PayAndreceiveItemObject.PayAndReceiveID = 1;
                PayAndRecieveItemFactoryObject.Edit(PayAndreceiveItemObject, int.Parse(textBox2.Text));
                MessageBox.Show("Update");

            }
            catch (SqlException ex)
            {

                MessageBox.Show(ex.Message);
            }
            catch(Exception ex)
            {
                MessageBox.Show(ex.Message);
            
            }

        }

        private void button4_Click(object sender, EventArgs e)
        {
            try
            {
                if (textBox6.Text.Trim()==null||textBox6.Text.Trim()==string.Empty)
                {
                    errorProvider1.SetError(textBox6, "نمی تواند خالی باشد");
                    textBox6.BackColor = Color.Yellow;
                }
                else
                {
                    PayAndRecieveItemFactoryObject.Remove(int.Parse(textBox6.Text));
                    MessageBox.Show("حذف شد");
                }

            }
            catch (SqlException ex)
            {

                MessageBox.Show(ex.Message);
            }
            catch(Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }

        private void PayAndReceiveItem_Load(object sender, EventArgs e)
        {
            dataGridView1.BackgroundColor = Color.WhiteSmoke;
            DataTable DT = new DataTable();
            PayAndRecieveItemFactoryObject.GetAll(DT);
            dataGridView1.DataSource = null;
            dataGridView1.DataSource = DT;
        }
    }
}
